<?php

/**
 * This is the model class for table "soldier".
 *
 * The followings are the available columns in table 'soldier':
 * @property integer $id
 * @property integer $serial_no
 * @property string $soldier_name
 * @property string $soldier_l_name
 * @property string $soldier_m_name
 * @property string $rank
 * @property string $birthday
 * @property string $branch_of_services
 *
 * The followings are the available model relations:
 * @property MainLedger[] $mainLedgers
 * @property NewLedger[] $newLedgers
 */
class Soldier extends CActiveRecord
{

const branch_of_services1='PAF';
	const branch_of_services2='PA';
	const branch_of_services3='PN';
	const branch_of_services4='PNM';

	
	
	public function getbranch_of_services(){
		return array(
				self::branch_of_services1=>'PAF',
				self::branch_of_services2=>'PA',
				self::branch_of_services3=>'PN',
				self::branch_of_services4=>'PNM',
					
			);
	}

	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Soldier the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'soldier';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('serial_no, soldier_name, soldier_l_name, soldier_m_name, rank, birthday', 'required'),
			array('serial_no', 'numerical', 'integerOnly'=>true),
			array('soldier_name, soldier_l_name, soldier_m_name, rank, branch_of_services', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, serial_no, soldier_name, soldier_l_name, soldier_m_name, rank, birthday, branch_of_services', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'mainLedgers' => array(self::HAS_MANY, 'MainLedger', 'soldier_id'),
			'newLedgers' => array(self::HAS_MANY, 'NewLedger', 'soldier_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'serial_no' => 'Serial No',
			'soldier_name' => 'Soldier Name',
			'soldier_l_name' => 'Soldier L Name',
			'soldier_m_name' => 'Soldier M Name',
			'rank' => 'Rank',
			'birthday' => 'Birthday',
			'branch_of_services' => 'Branch Of Services',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('serial_no',$this->serial_no);
		$criteria->compare('soldier_name',$this->soldier_name,true);
		$criteria->compare('soldier_l_name',$this->soldier_l_name,true);
		$criteria->compare('soldier_m_name',$this->soldier_m_name,true);
		$criteria->compare('rank',$this->rank,true);
		$criteria->compare('birthday',$this->birthday,true);
		$criteria->compare('branch_of_services',$this->branch_of_services,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}